<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="申报人" prop="userName">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入申报人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="村" prop="village">
        <el-input
          v-model="queryParams.village"
          placeholder="请输入村"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="男方姓名" prop="manName">
        <el-input
          v-model="queryParams.manName"
          placeholder="请输入男方姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="manPhone">
        <el-input
          v-model="queryParams.manPhone"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="整治面貌" prop="manPoliticalOutlook">
        <el-input
          v-model="queryParams.manPoliticalOutlook"
          placeholder="请输入整治面貌"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工作单位" prop="manWork">
        <el-input
          v-model="queryParams.manWork"
          placeholder="请输入工作单位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="于逝者关系" prop="deceasedRelation">
        <el-input
          v-model="queryParams.deceasedRelation"
          placeholder="请输入于逝者关系"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="逝者姓名" prop="deceasedName">
        <el-input
          v-model="queryParams.deceasedName"
          placeholder="请输入逝者姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="年龄" prop="deceasedAge">
        <el-input
          v-model="queryParams.deceasedAge"
          placeholder="请输入年龄"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="时间" prop="affairTime">
        <el-input
          v-model="queryParams.affairTime"
          placeholder="请输入时间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="办理地点" prop="affairPlace">
        <el-input
          v-model="queryParams.affairPlace"
          placeholder="请输入办理地点"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="场地名称" prop="affairPlaceName">
        <el-input
          v-model="queryParams.affairPlaceName"
          placeholder="请输入场地名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="宴请人数" prop="peopleNum">
        <el-input
          v-model="queryParams.peopleNum"
          placeholder="请输入宴请人数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车辆数" prop="carNum">
        <el-input
          v-model="queryParams.carNum"
          placeholder="请输入车辆数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车辆来源" prop="carSource">
        <el-input
          v-model="queryParams.carSource"
          placeholder="请输入车辆来源"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否包含外地返回人员" prop="outlander">
        <el-input
          v-model="queryParams.outlander"
          placeholder="请输入是否包含外地返回人员"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="外来人员数" prop="outlanderNum">
        <el-input
          v-model="queryParams.outlanderNum"
          placeholder="请输入外来人员数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否来自高风险地区" prop="highRisk">
        <el-input
          v-model="queryParams.highRisk"
          placeholder="请输入是否来自高风险地区"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="高风险地区" prop="highRiskPlace">
        <el-input
          v-model="queryParams.highRiskPlace"
          placeholder="请输入高风险地区"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否邀请健康码为红、黄码或有发热、干咳、咽痛、乏力、腹泻" prop="abnormalMan">
        <el-input
          v-model="queryParams.abnormalMan"
          placeholder="请输入是否邀请健康码为红、黄码或有发热、干咳、咽痛、乏力、腹泻"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="异常症状者" prop="abnormalManName">
        <el-input
          v-model="queryParams.abnormalManName"
          placeholder="请输入异常症状者"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:whiteaffair:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:whiteaffair:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:whiteaffair:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:whiteaffair:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="whiteaffairList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="${comment}" align="center" prop="id" />
      <el-table-column label="申报人" align="center" prop="userName" />
      <el-table-column label="村" align="center" prop="village" />
      <el-table-column label="男方姓名" align="center" prop="manName" />
      <el-table-column label="${comment}" align="center" prop="manPhone" />
      <el-table-column label="性别" align="center" prop="manSex" />
      <el-table-column label="整治面貌" align="center" prop="manPoliticalOutlook" />
      <el-table-column label="工作单位" align="center" prop="manWork" />
      <el-table-column label="于逝者关系" align="center" prop="deceasedRelation" />
      <el-table-column label="逝者姓名" align="center" prop="deceasedName" />
      <el-table-column label="年龄" align="center" prop="deceasedAge" />
      <el-table-column label="性别" align="center" prop="deceasedSex" />
      <el-table-column label="时间" align="center" prop="affairTime" />
      <el-table-column label="办理地点" align="center" prop="affairPlace" />
      <el-table-column label="场地名称" align="center" prop="affairPlaceName" />
      <el-table-column label="宴请人数" align="center" prop="peopleNum" />
      <el-table-column label="车辆数" align="center" prop="carNum" />
      <el-table-column label="车辆来源" align="center" prop="carSource" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="是否包含外地返回人员" align="center" prop="outlander" />
      <el-table-column label="外来人员数" align="center" prop="outlanderNum" />
      <el-table-column label="是否来自高风险地区" align="center" prop="highRisk" />
      <el-table-column label="高风险地区" align="center" prop="highRiskPlace" />
      <el-table-column label="是否邀请健康码为红、黄码或有发热、干咳、咽痛、乏力、腹泻" align="center" prop="abnormalMan" />
      <el-table-column label="异常症状者" align="center" prop="abnormalManName" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:whiteaffair:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:whiteaffair:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改白事对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="申报人" prop="userName">
          <el-input v-model="form.userName" placeholder="请输入申报人" />
        </el-form-item>
        <el-form-item label="村" prop="village">
          <el-input v-model="form.village" placeholder="请输入村" />
        </el-form-item>
        <el-form-item label="男方姓名" prop="manName">
          <el-input v-model="form.manName" placeholder="请输入男方姓名" />
        </el-form-item>
        <el-form-item label="${comment}" prop="manPhone">
          <el-input v-model="form.manPhone" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="整治面貌" prop="manPoliticalOutlook">
          <el-input v-model="form.manPoliticalOutlook" placeholder="请输入整治面貌" />
        </el-form-item>
        <el-form-item label="工作单位" prop="manWork">
          <el-input v-model="form.manWork" placeholder="请输入工作单位" />
        </el-form-item>
        <el-form-item label="于逝者关系" prop="deceasedRelation">
          <el-input v-model="form.deceasedRelation" placeholder="请输入于逝者关系" />
        </el-form-item>
        <el-form-item label="逝者姓名" prop="deceasedName">
          <el-input v-model="form.deceasedName" placeholder="请输入逝者姓名" />
        </el-form-item>
        <el-form-item label="年龄" prop="deceasedAge">
          <el-input v-model="form.deceasedAge" placeholder="请输入年龄" />
        </el-form-item>
        <el-form-item label="时间" prop="affairTime">
          <el-input v-model="form.affairTime" placeholder="请输入时间" />
        </el-form-item>
        <el-form-item label="办理地点" prop="affairPlace">
          <el-input v-model="form.affairPlace" placeholder="请输入办理地点" />
        </el-form-item>
        <el-form-item label="场地名称" prop="affairPlaceName">
          <el-input v-model="form.affairPlaceName" placeholder="请输入场地名称" />
        </el-form-item>
        <el-form-item label="宴请人数" prop="peopleNum">
          <el-input v-model="form.peopleNum" placeholder="请输入宴请人数" />
        </el-form-item>
        <el-form-item label="车辆数" prop="carNum">
          <el-input v-model="form.carNum" placeholder="请输入车辆数" />
        </el-form-item>
        <el-form-item label="车辆来源" prop="carSource">
          <el-input v-model="form.carSource" placeholder="请输入车辆来源" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label="是否包含外地返回人员" prop="outlander">
          <el-input v-model="form.outlander" placeholder="请输入是否包含外地返回人员" />
        </el-form-item>
        <el-form-item label="外来人员数" prop="outlanderNum">
          <el-input v-model="form.outlanderNum" placeholder="请输入外来人员数" />
        </el-form-item>
        <el-form-item label="是否来自高风险地区" prop="highRisk">
          <el-input v-model="form.highRisk" placeholder="请输入是否来自高风险地区" />
        </el-form-item>
        <el-form-item label="高风险地区" prop="highRiskPlace">
          <el-input v-model="form.highRiskPlace" placeholder="请输入高风险地区" />
        </el-form-item>
        <el-form-item label="是否邀请健康码为红、黄码或有发热、干咳、咽痛、乏力、腹泻" prop="abnormalMan">
          <el-input v-model="form.abnormalMan" placeholder="请输入是否邀请健康码为红、黄码或有发热、干咳、咽痛、乏力、腹泻" />
        </el-form-item>
        <el-form-item label="异常症状者" prop="abnormalManName">
          <el-input v-model="form.abnormalManName" placeholder="请输入异常症状者" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listWhiteaffair, getWhiteaffair, delWhiteaffair, addWhiteaffair, updateWhiteaffair } from "@/api/system/whiteaffair";

export default {
  name: "Whiteaffair",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 白事表格数据
      whiteaffairList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userName: null,
        village: null,
        manName: null,
        manPhone: null,
        manSex: null,
        manPoliticalOutlook: null,
        manWork: null,
        deceasedRelation: null,
        deceasedName: null,
        deceasedAge: null,
        deceasedSex: null,
        affairTime: null,
        affairPlace: null,
        affairPlaceName: null,
        peopleNum: null,
        carNum: null,
        carSource: null,
        outlander: null,
        outlanderNum: null,
        highRisk: null,
        highRiskPlace: null,
        abnormalMan: null,
        abnormalManName: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询白事列表 */
    getList() {
      this.loading = true;
      listWhiteaffair(this.queryParams).then(response => {
        this.whiteaffairList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        userName: null,
        village: null,
        manName: null,
        manPhone: null,
        manSex: null,
        manPoliticalOutlook: null,
        manWork: null,
        deceasedRelation: null,
        deceasedName: null,
        deceasedAge: null,
        deceasedSex: null,
        affairTime: null,
        affairPlace: null,
        affairPlaceName: null,
        peopleNum: null,
        carNum: null,
        carSource: null,
        remark: null,
        outlander: null,
        outlanderNum: null,
        highRisk: null,
        highRiskPlace: null,
        abnormalMan: null,
        abnormalManName: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加白事";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getWhiteaffair(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改白事";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateWhiteaffair(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addWhiteaffair(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除白事编号为"' + ids + '"的数据项？').then(function() {
        return delWhiteaffair(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/whiteaffair/export', {
        ...this.queryParams
      }, `whiteaffair_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
